<?php

class Package_model extends CI_Model
{

	private $table = 'group6_tbl_package';

	public $user_id = 0;

	public function get_all()
	{
		return $this->db->get($this->table);
	}

	public function get_all_by_user_id($id)
	{
		$this->db->where('user_id', $id);
		$this->db->where('enable', true);
		return $this->db->get($this->table);
	}

	public function add_by_post($post)
	{
		$insert_data = [
			'user_id'	   => $this->user_id,
			'package_name' => $post['name'],
			'price'		   => $post['price'],
			'serve_time'   => $post['serve_time'],
			'description'  => $post['description'],
			'enable'	   => true
		];

		$this->db->insert($this->table, $insert_data);
	}

	public function get_by_id($id)
	{
		$this->db->select('*');
		$this->db->join('group6_tbl_user u', 'u.user_id = ' . $this->table . '.user_id');
		$this->db->join('group6_tbl_package_detail pd', 'pd.package_id = ' . $this->table .'.package_id');
		$this->db->join('group6_tbl_service s', 's.service_id = pd.service_id');
		$this->db->join('group6_tbl_supplier sp', 'sp.supplier_id = pd.supplier_id');

		return $this->db->get($this->table);
	}

	public function get_one_by_id($id)
	{
		$this->db->where('package_id', $id);
		return $this->db->get($this->table);
	}

}
